{"ast":null,"code":"'use strict';\n\n/**\n * Calculate data maxRate\n * @param {Number} [samplesCount= 10]\n * @param {Number} [min= 1000]\n * @returns {Function}\n */\nfunction speedometer(samplesCount, min) {\n  samplesCount = samplesCount || 10;\n  var bytes = new Array(samplesCount);\n  var timestamps = new Array(samplesCount);\n  var head = 0;\n  var tail = 0;\n  var firstSampleTS;\n  min = min !== undefined ? min : 1000;\n  return function push(chunkLength) {\n    var now = Date.now();\n    var startedAt = timestamps[tail];\n    if (!firstSampleTS) {\n      firstSampleTS = now;\n    }\n    bytes[head] = chunkLength;\n    timestamps[head] = now;\n    var i = tail;\n    var bytesCount = 0;\n    while (i !== head) {\n      bytesCount += bytes[i++];\n      i = i % samplesCount;\n    }\n    head = (head + 1) % samplesCount;\n    if (head === tail) {\n      tail = (tail + 1) % samplesCount;\n    }\n    if (now - firstSampleTS < min) {\n      return;\n    }\n    var passed = startedAt && now - startedAt;\n    return passed ? Math.round(bytesCount * 1000 / passed) : undefined;\n  };\n}\nexport default speedometer;","map":{"version":3,"names":["speedometer","samplesCount","min","bytes","Array","timestamps","head","tail","firstSampleTS","undefined","push","chunkLength","now","Date","startedAt","i","bytesCount","passed","Math","round"],"sources":["/Users/poppie/Desktop/development/messenger/app/frontend/node_modules/axios/lib/helpers/speedometer.js"],"sourcesContent":["'use strict';\n\n/**\n * Calculate data maxRate\n * @param {Number} [samplesCount= 10]\n * @param {Number} [min= 1000]\n * @returns {Function}\n */\nfunction speedometer(samplesCount, min) {\n  samplesCount = samplesCount || 10;\n  const bytes = new Array(samplesCount);\n  const timestamps = new Array(samplesCount);\n  let head = 0;\n  let tail = 0;\n  let firstSampleTS;\n\n  min = min !== undefined ? min : 1000;\n\n  return function push(chunkLength) {\n    const now = Date.now();\n\n    const startedAt = timestamps[tail];\n\n    if (!firstSampleTS) {\n      firstSampleTS = now;\n    }\n\n    bytes[head] = chunkLength;\n    timestamps[head] = now;\n\n    let i = tail;\n    let bytesCount = 0;\n\n    while (i !== head) {\n      bytesCount += bytes[i++];\n      i = i % samplesCount;\n    }\n\n    head = (head + 1) % samplesCount;\n\n    if (head === tail) {\n      tail = (tail + 1) % samplesCount;\n    }\n\n    if (now - firstSampleTS < min) {\n      return;\n    }\n\n    const passed = startedAt && now - startedAt;\n\n    return  passed ? Math.round(bytesCount * 1000 / passed) : undefined;\n  };\n}\n\nexport default speedometer;\n"],"mappings":"AAAA,YAAY;;AAEZ;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,WAAW,CAACC,YAAY,EAAEC,GAAG,EAAE;EACtCD,YAAY,GAAGA,YAAY,IAAI,EAAE;EACjC,IAAME,KAAK,GAAG,IAAIC,KAAK,CAACH,YAAY,CAAC;EACrC,IAAMI,UAAU,GAAG,IAAID,KAAK,CAACH,YAAY,CAAC;EAC1C,IAAIK,IAAI,GAAG,CAAC;EACZ,IAAIC,IAAI,GAAG,CAAC;EACZ,IAAIC,aAAa;EAEjBN,GAAG,GAAGA,GAAG,KAAKO,SAAS,GAAGP,GAAG,GAAG,IAAI;EAEpC,OAAO,SAASQ,IAAI,CAACC,WAAW,EAAE;IAChC,IAAMC,GAAG,GAAGC,IAAI,CAACD,GAAG,EAAE;IAEtB,IAAME,SAAS,GAAGT,UAAU,CAACE,IAAI,CAAC;IAElC,IAAI,CAACC,aAAa,EAAE;MAClBA,aAAa,GAAGI,GAAG;IACrB;IAEAT,KAAK,CAACG,IAAI,CAAC,GAAGK,WAAW;IACzBN,UAAU,CAACC,IAAI,CAAC,GAAGM,GAAG;IAEtB,IAAIG,CAAC,GAAGR,IAAI;IACZ,IAAIS,UAAU,GAAG,CAAC;IAElB,OAAOD,CAAC,KAAKT,IAAI,EAAE;MACjBU,UAAU,IAAIb,KAAK,CAACY,CAAC,EAAE,CAAC;MACxBA,CAAC,GAAGA,CAAC,GAAGd,YAAY;IACtB;IAEAK,IAAI,GAAG,CAACA,IAAI,GAAG,CAAC,IAAIL,YAAY;IAEhC,IAAIK,IAAI,KAAKC,IAAI,EAAE;MACjBA,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